#include <iostream>
#include <thread>
#include <vector>
#include "loader.h"

std::mutex cout_m; // mutex for cout

void look(Loader<Dictionary> &ld, int i)
{
    std::lock_guard lk(cout_m);
    std::cout << i << " " << ld->look_up(1) << std::endl;
}

int main()
{
    Loader<Dictionary> &ld = Loader<Dictionary>::get_instance();
    std::vector<std::thread> t;

    for (auto i = 0; i < 100; ++i)
    {
        if (i % 10 == 0)

            ld.load(std::make_shared<Dictionary>(i / 10));

        t.emplace_back([&ld, i]() {
            for (auto j = 1; j < 10; ++j)
                try
                {
                    look(ld, i);
                }
                catch (const char *)
                {
                }
        });
    }

    for (auto i = 0; i < 100; ++i)
    {
        t[i].join();
    }

    return 0;
}